package com.itfreer.gis.service;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.itfreer.form.api.BaseDao;
import com.itfreer.form.api.imp.DictionaryConvertServiceImp;
import com.itfreer.gis.dao.IGisAnalysisConfigDao;
import com.itfreer.gis.dao.IGisAnalysisDetailsViewDao;
import com.itfreer.gis.entity.GisAnalysisConfigEntity;
import com.itfreer.gis.entity.GisAnalysisDetailsViewEntity;
import com.itfreer.gis.entity.GisAnalysisShowFieldEntity;
import com.itfreer.gis.entity.GisStatisticsCategoryEntity;
import com.itfreer.gis.entity.GisStatisticsFieldEntity;
/**
 * 统计分析图层配置详情的视图
 * @author gj
 *
 */
@Component
public class GisAnalysisDetailsViewServiceImp extends DictionaryConvertServiceImp<GisAnalysisDetailsViewEntity> implements IGisAnalysisDetailsViewService {

	@Autowired
	private IGisAnalysisDetailsViewDao GisAnalysisDetailsViewDao;
	
	@Autowired
	private IGisAnalysisConfigDao GisAnalysisConfigDao;

	@Override
	protected BaseDao<GisAnalysisDetailsViewEntity> getDao() {
		return GisAnalysisDetailsViewDao;
	}
	
	/**
	 * 添加实体
	 * @param entity		添加实体
	 * @return
	 * @throws IOException 
	 */
	@Override
	public GisAnalysisDetailsViewEntity add(GisAnalysisDetailsViewEntity entity) {
		GisAnalysisConfigEntity nEntity=(GisAnalysisConfigEntity)entity;
		if(nEntity.getStatisticsCateory()!=null && nEntity.getStatisticsCateory().size()>0) {
			for(GisStatisticsCategoryEntity iTem:nEntity.getStatisticsCateory()) {
				iTem.setPid(nEntity.getId());
			}
		}
		
		if(nEntity.getStatisticsField()!=null && nEntity.getStatisticsField().size()>0) {
			for(GisStatisticsFieldEntity iTem:nEntity.getStatisticsField()) {
				iTem.setPid(nEntity.getId());
			}
		}
		
		if(nEntity.getShowField()!=null && nEntity.getShowField().size()>0) {
			for(GisAnalysisShowFieldEntity iTem:nEntity.getShowField()) {
				iTem.setPid(nEntity.getId());
			}
		}
		this.GisAnalysisConfigDao.add(nEntity);
		return entity;
	}
	
	@Override
	public GisAnalysisDetailsViewEntity update(GisAnalysisDetailsViewEntity entity) {
		GisAnalysisConfigEntity nEntity=(GisAnalysisConfigEntity)entity;
		if(nEntity.getStatisticsCateory()!=null && nEntity.getStatisticsCateory().size()>0) {
			for(GisStatisticsCategoryEntity iTem:nEntity.getStatisticsCateory()) {
				iTem.setPid(nEntity.getId());
			}
		}
		
		if(nEntity.getStatisticsField()!=null && nEntity.getStatisticsField().size()>0) {
			for(GisStatisticsFieldEntity iTem:nEntity.getStatisticsField()) {
				iTem.setPid(nEntity.getId());
			}
		}
		if(nEntity.getShowField()!=null && nEntity.getShowField().size()>0) {
			for(GisAnalysisShowFieldEntity iTem:nEntity.getShowField()) {
				iTem.setPid(nEntity.getId());
			}
		}
		this.GisAnalysisConfigDao.update(nEntity);
		return entity;
	}
	
	@Override
	public void delete(String guid) {
		this.GisAnalysisConfigDao.delete(guid);
	}
	
	@Override
	public void deletes(String guids) {
		this.GisAnalysisConfigDao.deletes(guids);
	}
}
